
cc.Class({
    extends: cc.Component,

    properties: {
        btnStart:cc.Button,
        btnShare:cc.Button,
        btnSetting:cc.Button,
        btnQiuPiFu:cc.Button,
        btnGangPiFu:cc.Button,
        btnRank:cc.Button,
        pfLevel:cc.Prefab,
        pfSetting:cc.Prefab,
        pfShop:cc.Prefab,
        txtLevel:cc.Label,
        txtGold:cc.Label,
        // audioMgr:audio,
    },

    onLoad () {
    },

    start(){
        this.init();
        if(window.gameConfig.isOpenMusic == "1")window.audioMgr.prototype.playGameMusic(true);

        this.txtGold.string = window.gameConfig.gold;
        let level = window.gameConfig.getGameConfigData("level");
        if(level == null)level = 1;
        this.txtLevel.string = "第" + level + "关";
        cc.director.preloadScene("gameMain");
    },

    init(){
        window.gameConfig = new require("gameConfig").prototype;
        window.audioMgr = new require("audioMgr");
        window.gameConfig.init();
    },

    //进入游戏
    onBtnStartCheckEvent:function(){
         window.audioMgr.prototype.playButtonAudio();
        //跳转关卡选择
        let level = creatrPrefab(this.pfLevel);
        this.node.addChild(level);
    },
 
    //分享
    onBtnShareCheckEvent:function(){
        window.audioMgr.prototype.playButtonAudio();
    },

    //排行榜
    onBtnRankCheckEvent:function(){
        window.audioMgr.prototype.playButtonAudio();
    },

    //设置
    onBtnSettingCheckEvent:function(){
        window.audioMgr.prototype.playButtonAudio();
        //加载设置界面prefab
        let pfSettingView = creatrPrefab(this.pfSetting);
        this.node.addChild(pfSettingView)
    },

    //皮肤选择 1----篮球  0-----弹杆
    onPiFuSelectCheckEvent:function(type, custom){
        window.audioMgr.prototype.playButtonAudio();
        //加载皮肤选择界面prefab并根据参数加载篮球或弹杆的皮肤图片
        //加载设置界面prefab
        let pfShop = creatrPrefab(this.pfShop);
        let shop = pfShop.getComponent("gameShop");
        if(custom == 1)
        {
            shop.setShopType("ball");
        }
        else
        {
            shop.setShopType("gan");
        }

        this.node.addChild(pfShop);
    },
});
